<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增图片存储')"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-image-add">
        <div class="form-group">
            <label class="col-sm-3 control-label">图片名称：</label>
            <div class="col-sm-8">
                <input name="name" class="form-control" type="text">
            </div>
        </div>
        <!--            <div class="form-group">    -->
        <!--                <label class="col-sm-3 control-label">图片地址：</label>-->
        <!--                <div class="col-sm-8">-->
        <!--                    <input name="url" class="form-control" type="text">-->
        <!--                </div>-->
        <!--            </div>-->
        <div class="form-group">
            <label class="font-noraml">多文件上传</label>
            <div class="file-loading">
                <input id="multipleFile" name="files" type="file" multiple>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<script th:inline="javascript">
    var prefix = ctx + "fireman/image"
    $("#form-image-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-image-add').serialize());
        }
    }

    // 多图上传
    $("#multipleFile").fileinput({
        uploadUrl: ctx + 'common/uploads',
        uploadAsync: false
    }).on('filebatchuploadsuccess', function (event, data, previewId, index) {
        var rsp = data.response;
        log.info("return urls：" + rsp.urls)
        log.info("reutrn fileNames：" + rsp.fileNames)
        if (rsp.urls) {
            console.log("开始切分数组")
            let myUrls = rsp.urls.split(",");
            $(myUrls).each(function (index, obj) {
                let urlInput = $("<input type='hidden' name='urls'/>");
                urlInput.val(obj);
                urlInput.appendTo($("#form-image-add"));
            })
        }

    }).on('fileremoved', function (event, id, index) {
        $("input[name='" + event.currentTarget.id + "']").val('')
    })
</script>
</body>
</html>